package src.origintrail;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.*;

/**
 * The main program class
 * @author csmythe
 */
public class OriginTrail {
    /**
     * The player. Please don't be stupid and spawn another one...
     */
    public static Player plr;
    /**
     * Determines whether or not to exit
     */
    public static boolean exitFlag = true;

    /**
     * Main frame
     */
    public static final JFrame otFrame = new JFrame("OriginTrail");
    /**
     * Anim panel
     */
    public static final AnimationPanel animPanel = new AnimationPanel();
    /**
     * information panel (not implemented yet)
     */
    public static final JPanel infoPanel = new JPanel();
    /**
     * UI elements
     */
    public static final JPanel uiPanel = new JPanel();
    public static final JPanel shopPanel = new JPanel();
    public static final JPanel startPanel = new JPanel();
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        ImageIcon splash = new ImageIcon("src/origintrail/images/splash.jpg");;
        JLabel imageLabel = new JLabel(splash);
        otFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        animPanel.setLayout(new GridBagLayout());
        infoPanel.setLayout(new SpringLayout());
        uiPanel.setLayout(new BorderLayout());
        animPanel.setPreferredSize(new Dimension(800,480));
        infoPanel.setPreferredSize(new Dimension(800,0));
        uiPanel.setPreferredSize(new Dimension(800,20));
        otFrame.setPreferredSize(new Dimension(700,600));
        shopPanel.setPreferredSize(new Dimension(800,20));
        otFrame.getContentPane().setLayout(new BoxLayout(otFrame.getContentPane(), BoxLayout.Y_AXIS));
        otFrame.setResizable(true);
        otFrame.add(animPanel);
        otFrame.add(infoPanel);
        otFrame.add(uiPanel);
        otFrame.add(startPanel);
        otFrame.add(shopPanel);
        shopPanel.setVisible(false);
        otFrame.setVisible(true);
		animPanel.add(imageLabel);
        otFrame.pack();
 //       animPanel.setPreferredSize(new Dimension(640, 480));
        animPanel.repaint();
        otFrame.setResizable(false);
        otFrame.setVisible(true);
      

        EvtSpawner.instance.spawnStartEvent();
        while(!EvtSpawner.instance.getHandler().isEmpty() && exitFlag)
        {
            try{
                EvtSpawner.instance.getHandler().pop().activate();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
}
